#include"RingBuffer.hpp"
#include<unistd.h>
#include<time.h>

using namespace RingBufferModule;

void* consumer(void* args);
void* producer(void* args);

int main()
{
    RingBuffer<int> rb(10);
    pthread_t p1,c1;
    pthread_create(&p1,NULL,producer,&rb);
    pthread_create(&c1,NULL,consumer,&rb);

    pthread_join(p1,NULL);
    pthread_join(c1,NULL);
    return 0;
}

void* consumer(void* args)
{
    RingBuffer<int>* rb=static_cast<RingBuffer<int>*>(args);
    while(1)
    {
        int data;
        rb->Pop(&data);
        printf("get data:%d\n",data);
        sleep(1);
    }
}

void* producer(void* args)
{
    RingBuffer<int>* rb=static_cast<RingBuffer<int>*>(args);
    while(1)
    {
        int data=rand()%100;
        rb->Equeue(data);
        printf("push data:%d\n",data);
        sleep(1);
    }
}